﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EngineOfEvermore.Imaging;
using Blue.ResourceManager;
using System.Diagnostics;

namespace EngineOfEvermore.Editor.AnimationEditor.Model
{
    class AnimationEditorModel : IAnimationEditorModel
    {
        List<IDocumentModel> _documents = new List<IDocumentModel>();

        public IEnumerable<IDocumentModel> Documents
        {
            get { return _documents; }
        }

        public IDocumentModel CreateNewDocument()
        {
            DocumentModel doc = new DocumentModel();

            doc.NameOfRepresentedResource = null;
            doc.RepresentsResource = false;

            _documents.Add( doc );
            return doc;
        }

        public IDocumentModel LoadResourceAsDocument( String resourceName )
        {
            resourceName = ResourceManager.NormalizeName( resourceName );

            Debug.Assert( ResourceManager.ResourceExists( resourceName ) );

            FrameAnimation animation =
                ResourceManager.GetResource<FrameAnimation>( resourceName );

            DocumentModel doc = new DocumentModel();

            doc.EditedAnimation = animation.CreateEdibleFrameAnimation();
            doc.RepresentsResource = true;
            doc.NameOfRepresentedResource = resourceName;

            _documents.Add( doc );
            return doc;
        }

        public void DestroyDocument( IDocumentModel documentModel )
        {
            _documents.Remove( documentModel );
        }
    }
}
